#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time   : 2021/4/17 19:24
# @Author : cjw
"""部门管理"""
from business.login import LoginPage
from util.file_reader import YmlReader
from setting.setting import YAML_ELEMENT
from util.generator import random_word, random_num
from time import sleep


class PartManagementPage(LoginPage):
    LoginPage.locators.update(YmlReader(YAML_ELEMENT['dmp']).data)

    def get_into_main(self):
        """进入部门管理主页"""
        self.basci_info.click()
        self.click_or_script_click(self.part)

    def add_department(self, name: str = random_word()):
        """新增部门"""
        self.click_or_script_click(self.add_part)
        self.part_num.send_keys(random_num())
        self.part_name.send_keys(name)
        self.click_or_script_click(self.part_submit)
        sleep(1)

    def add_sub_department(self, name: str = random_word()):
        """新增下级部门"""
        self.click_or_script_click(self.add_sub_part)
        self.part_num.send_keys(random_num())
        self.part_name.send_keys(name)
        self.click_or_script_click(self.part_submit)
        sleep(1)

    def binding_faculty(self):
        """绑定教职工"""
        self.click_or_script_click(self.binding_teacher)
        self.click_or_script_click(self.checkbox)
        self.click_or_script_click(self.binding_btn)
        self.click_or_script_click(self.part_submit)
        sleep(1)

    def unbinding_faculty(self):
        """解绑教职工"""
        self.click_or_script_click(self.binding_teacher)
        self.click_or_script_click(self.elements(self.locators['checkbox'])[1])
        self.click_or_script_click(self.binding_btn)
        self.click_or_script_click(self.part_submit)
        sleep(1)

    def edit_department(self, name: str = random_word()):
        """编辑部门信息"""
        self.click_or_script_click(self.edit)
        self.clear_and_send_keys(self.part_num, random_num())
        self.clear_and_send_keys(self.part_name, name)
        self.click_or_script_click(self.part_submit)
        sleep(1)

    def delete_department(self):
        """删除部门"""
        self.click_or_script_click(self.delete)
        self.click_or_script_click(self.part_submit)
        sleep(1)


if __name__ == '__main__':
    obj = PartManagementPage()
    obj.get()
    obj.login()
    obj.get_into_main()
    obj.add_department()
    obj.driver.quit()
